PageMac
Home
   dot Projects
   dot Pics and Images
   dot WREK
D++
   dot About / FAQ
   dot Download
   dot Code Library
   dot Documentation
   dot VB6 Runtime Files
About

  Source Code - dpp/source/winsock client.dpp

Download link (right click, save as)



1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
function main()
{
    title "Winsock Test";
    winsock test;
    
    screenput "Connecting...";

    sock[test].connect("127.0.0.1", 500);
}

function test_connect()
{
    newvar command;
    screenput "Connected!"; screen;

    do until command="exit";
        screenput "you> ";
        screenin command; screen;
        if command = "" then
            return;
        endif
        sock[test].send(command);
    loop
    sock[test].close();
    end;
}

function test_incoming(data, bytesTotal)
{
    screen;
    call addtextinput("server> " & data);
}

function test_close()
{
    screen;
    call addtextinput("Connection closed.");
    cancel_input;
    call addtext("Terminating program.");
    finish;
}

function test_error(number, description)
{
    screen;
    call addtextinput("Error: " & description);
}

function addtextinput(text)
{
    'this adds text on the second to last line... so your input does't mess up
    newvar i, n;
    newvar var1, var2;

    for i = conlen() to 1 step -1;
    if mid(getconsole(), i, 2) = dpp.crlf then
        n++;
        if n = 2 then
            var1 = mid(getconsole(), 1, i + 1);
            var2 = mid(getconsole(), i + 2);
            var2 = left(var2, len(var2) - 2);
            call setconsole(var1 & text & dpp.crlf & var2);
                call setstart(conlen());
                doevents;
                return;
        endif
    endif
    next i;

    call AddText(text);
}

function addtext(text)
{
    'just adds text to the screen
    screenput text; screen;
}òõÿòõÿ


This code is Copyright (C) 2000-2012 PageMac Programming. Reproduction of this code must adhere to the GNU General Public License.